<%--
  Created by IntelliJ IDEA.
  User: 3353611694
  Date: 2022/5/18
  Time: 11:21
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>班级管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <script>
        layui.use(['table','util','jquery','layer','form'],function () {
            var table = layui.table,util=layui.util,$=layui.jquery,layer=layui.layer,form=layui.form;
            //监听工具栏的按钮  修改，删除
            var table = layui.table,
                $=layui.jquery,
                layer= layui.layer,
                form = layui.form,
                upload = layui.upload
            element = layui.element;

            table.on('tool(demo)',function (res) {
                var row = res.data; //获取当前行的数据
                var event = res.event; //获取是哪个按钮
                var calssTypeId = row.calssTypeId;
                // alert(event+" "+calssTypeId);
                if (event=='del'){
                    //把id传到后台去删除
                    // alert(row.empId); 弹出要删除的ID
                    layer.confirm('是否删除该班级？',{
                        btn:['确定','取消']
                    },function () {//确定的回调函数
                        // alert(row.empId);测试是否进入
                        $.post("${pageContext.request.contextPath}/juris/delbanji",{calssTypeId:calssTypeId},function (data) {
                            layer.msg(data.msg);  //使用消息层 显示删除结果
                            //重新加载table
                            table.reload('demo',{
                                url:"${pageContext.request.contextPath}/juris/banji"
                            });
                        },"json");
                    });
                }else  if (event=='edit'){
                    layer.open({
                        type:2,
                        fix:false,
                        maxmin:true,
                        offset:'5px',
                        shadeClose:true,
                        shade:0.4,
                        area:['550px','350px'],
                        title:"编辑班级",
                        content:'${pageContext.request.contextPath}/juris/toupbanji/'+calssTypeId
                    })
                }
            });
            form.verify({
                num_sz:[
                    /(^$)|^\d+$/,
                    '只能填写数字'
                ],
            });

            //监听from表单提交
            form.on('submit(search-btn)',function (d) {
                var calssTypeId = $("#calssTypeId").val();
                var classTypeName = $("#classTypeName").val();
                // alert("  "+calssTypeId+":"+classTypeName);
                table.reload('demo',{
                    page:{curr:1},
                    where:{ //条件
                        calssTypeId:calssTypeId,
                        classTypeName:classTypeName,
                    }
                })
            });
            //监听form表单提交  模糊查询  查看全部按钮
            form.on('submit(quanbu-btn)',function (d) {
                location.reload("demo");//重新加载父页面表格
            });
            //监听添加按钮
            $("#add-btn").click(function () {
                layer.open({
                    type:2,
                    fix:false,
                    maxmin:true,
                    offset:'5px',
                    shadeClose:true,
                    shade:0.4,
                    area:['550px','350px'],
                    title:"新增班级",
                    content:'${pageContext.request.contextPath}/juris/toaddbanji'
                });
            });

        });
    </script>
</head>
<body>
<div>
    <form class="layui-form" action="${pageContext.request.contextPath}">
        <div class="layui-inline">班级编号:</div>
        <div class="layui-inline">
            <input type="text" id="calssTypeId" name="calssTypeId" class="layui-input" lay-verify="num_sz"/>
        </div>
        <div class="layui-inline">班级名称:</div>
        <div class="layui-inline">
            <input type="text" id="classTypeName" name="classTypeName" class="layui-input" />
        </div>
        <a class="layui-btn" lay-filter="search-btn" lay-submit lay-size="sm" >搜索<i class="layui-icon">&#xe615;</i> </a>
        <a class="layui-btn" lay-filter="quanbu-btn" lay-submit="" lay-size="sm">刷新 <i class="layui-icon">&#xe669;</i></a>
        <button id="add-btn" type="button" class="layui-btn layui-btn-normal" style="position: absolute; right: 10px;">添加 <i class="layui-icon">&#xe654;</i></button>
    </form>
</div>
<table class="layui-table" id="demo" lay-filter="demo" lay-size="sm"
       lay-data="{url:'${pageContext.request.contextPath}/juris/banji',page:true,id:'demo'}">
    <thead>
    <tr>
        <th lay-data="{field:'calssTypeId',sort:true ,align:'center',style:'height:50px;'}">班级编号</th>
        <th lay-data="{field:'classTypeName',sort:true,align:'center'}">班级名称</th>
        <th lay-data="{toolbar:'#tools',width:300,align:'center',fixed:'right'}">操作</th>
    </tr>
    </thead>
</table>
<script type="text/html" id="tools">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" >删除</a>
</script>

